﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter15.Code04.KarliCards_GUI
{
    using System.ComponentModel;
    using System.Collections.ObjectModel;

    [Serializable]
    public class GameOptions : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private bool playAgainstComputer = true;
        public bool PlayAgainstComputer
        {
            get { return playAgainstComputer; }
            set
            {
                playAgainstComputer = value;
                OnPropertyChanged("PlayAgainstComputer"); 
            }
        }

        private int numberOfPlayers = 2;
        public int NumberOfPlayers
        {
            get { return numberOfPlayers; }
            set
            {
                numberOfPlayers = value;
                OnPropertyChanged("NumberOfPlayers"); 
            }
        }

        private int minutesBeforeLoss = 10;
        public int MinutesBeforeLoss
        {
            get { return minutesBeforeLoss; }
            set
            {
                minutesBeforeLoss = value;
                OnPropertyChanged("MinutesBeforeLoss"); 
            }
        }

        private ComputerSkillLevel computerSkill = ComputerSkillLevel.Dumb;
        public ComputerSkillLevel ComputerSkill
        {
            get { return computerSkill; }
            set
            {
                computerSkill = value;
                OnPropertyChanged("ComputerSkill"); 
            }
        }

        private ObservableCollection<string> playerNames = new ObservableCollection<string>();
        public ObservableCollection<string> PlayerNames
        {
            get { return playerNames; }
            set
            {
                playerNames = value;
                OnPropertyChanged("PlayerNames"); 
            }
        }

        public List<string> SelectedPlayers { get; set; }

        public GameOptions()
        {
            SelectedPlayers = new List<string>();
        }

        public void AddPlayer(string playerName)
        {
            if (playerNames.Contains(playerName)) return;
            playerNames.Add(playerName);
            OnPropertyChanged("PlayerNames");
        }
    }
}
